/*
 * Created on 28-ene-2012, 11:04:16
 */
package core.constructor;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenu;
import javax.swing.JPanel;
import tools.HiloActualizacion;
import v.Acudiente_View_Add;
import v.Acudiente_View_Grid;
import v.Cita_View_Add;
import v.Cita_View_Grid;
import v.Medicamentos_View_Add;
import v.Medicamentos_View_Grid;
import v.Medico_View_Add;
import v.Medico_View_Grid;
import v.Paciente_View_Add;
import v.Paciente_View_Grid;
import v.Planilla_View_Add;
import v.Planilla_View_Grid;
import v.SeleccionadorIU;
import v.TestNeuro_View_Grid;
import v.Trazabilidad;
import v.UsuarioPass_View_Grid;
import v.UsuariosAdmin_View_Add;
import v.UsuariosAdmin_View_Grid;
import v.Usuarios_Constructor;


/**
 * @author !gaso
 */
public class constructor extends javax.swing.JFrame {

    private String usuario; //Nombre Usuario del Sistema
    private String rol;     // Nombre Rol Usuario
    private String navegar; // Indicar a Migas de Pan cual Ventana Abrir.
    private static HiloActualizacion actualizarCitas = null;
    private static Thread hilo;
    private OcultarMensaje ocultarMensaje = new OcultarMensaje();

    //Constructor de Ventanas Modales
    Usuarios_Constructor usuarios;
    
    private void abrirParametrizacion() {
        if("administrador".equals(getRol())){
            //Abrir Ventana para gestion de usuarios
            usuarios = new Usuarios_Constructor();
            usuarios.setVisible(true);
            constructor("UsuariosAdmin_View_Grid", "");
        }else{
            //Abrir Ventana para cambiar contraseña
            UsuarioPass_View_Grid pass = new UsuarioPass_View_Grid(getUsuario());
            pass.setVisible(true);
        }
    }

    private class OcultarMensaje implements Runnable {

        private boolean iniciar = false;
        private boolean iniciado = false;
        private int contador = 0;

        @Override
        public void run() {
            try {
                iniciado = true;
                while (iniciar) {
                    if (contador == 0) {
                        panelColapsable.setCollapsed(true);
                        iniciar = iniciado = false;
                        break;
                    }
                    contador--;
                    Thread.sleep(1000);
                    if (!iniciar) {
                        iniciado = false;
                    }

                }
            } catch (InterruptedException ex) {
                Logger.getLogger(constructor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        public boolean isIniciado() {
            return iniciado;
        }

        public boolean isIniciar() {
            return iniciar;
        }

        public void setIniciar(boolean iniciar) {
            this.iniciar = iniciar;

            contador = 30;
        }
    };

    /**
     * o[0] = Trama de Seguridad (usuario:rol:permisos)
     *
     * @param o
     */
    //Object... o
    public constructor(Object... o) {
        initComponents();

        /**
         * Asignarle Nombre a JComponents con Permisos
         * -------------------------------------------
         *
         * Deben llamarse igual que en la tabla de la BD.
         */
        //JMenu
        pacientes.setName("pacientes");
        medicos.setName("medicos");
        citas.setName("citas");
        historia.setName("citas");
        inicio.setName("inicio");
        configuracion.setName("configuracion");

        System.out.println("Hola! " + this.getClass().getSimpleName());

        System.out.println("");

        config(o);


        constructor("Bienve_" + getRol());
        panelColapsable.setCollapsed(true);

        if (null == hilo && null == actualizarCitas) {
            actualizarCitas = HiloActualizacion.getSingle();
            actualizarCitas.setIniciar(true);
            hilo = new Thread(actualizarCitas);
            hilo.start();
        }

//        if(null == hiloMensaje){
//            ocultarMensaje = new OcultarMensaje();
//            hiloMensaje = new Thread(ocultarMensaje);
//        }

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(WindowEvent winEv) {
                System.out.println("Parando hilo");
                if (null != actualizarCitas) {
                    actualizarCitas.setIniciar(false);
                    ocultarMensaje.setIniciar(false);
                }
            }
        });
        //informarUsuario("ok[¡Informacion Ingresada Correctamente!] Se ha ingresado al Sistema <strong>" + "El Elemento" + "</strong> de forma satisfactoria.");

        this.setLocationRelativeTo(null);
        
        setTitle(".:. Fundación Superar - Sistema de Control y Gestión .:.");
    }

    /**
     * <strong>config</strong><br> Configura los parametros que provienen del
     * constructor de la clase.<br> e[0] - contiene el JFrame 'padre'.
     *
     * @param e
     */
    private void config(Object... e) {
        if (e.length > 0) {
            setAccess((List) e[0], (String) e[1] , (String) e[2]);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lAccion = new javax.swing.JLabel();
        lModulo = new javax.swing.JLabel();
        PanelConstructor = new javax.swing.JPanel();
        panelColapsable = new org.jdesktop.swingx.JXCollapsiblePane();
        PanelInformacion = new org.jdesktop.swingx.JXPanel();
        IconoInformacion = new javax.swing.JLabel();
        LInformacion = new javax.swing.JLabel();
        Menu = new javax.swing.JMenuBar();
        inicio = new javax.swing.JMenu();
        configuracion = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        backups = new javax.swing.JMenuItem();
        salir = new javax.swing.JMenuItem();
        pacientes = new javax.swing.JMenu();
        Paciente_View_Grid = new javax.swing.JMenuItem();
        Paciente_View_Add = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        Acudiente_View_Grid = new javax.swing.JMenuItem();
        Acudiente_View_Add = new javax.swing.JMenuItem();
        medicos = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMedicoItem = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        citas = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        historia = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));

        jLabel1.setFont(new java.awt.Font("Helvetica Neue", 0, 36)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/LogoFundacion.png"))); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        lAccion.setFont(new java.awt.Font("Helvetica Neue", 0, 24)); // NOI18N
        lAccion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/icono_mod.png"))); // NOI18N

        lModulo.setFont(new java.awt.Font("Helvetica Neue", 0, 36)); // NOI18N
        lModulo.setText("Inicio");
        lModulo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lModuloMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lModuloMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lModuloMouseExited(evt);
            }
        });

        PanelConstructor.setLayout(new java.awt.GridLayout(1, 0));

        PanelInformacion.setBackground(java.awt.SystemColor.activeCaption);
        PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/informacion64.png"))); // NOI18N

        LInformacion.setFont(new java.awt.Font("Helvetica Neue", 0, 14)); // NOI18N
        LInformacion.setForeground(new java.awt.Color(255, 102, 0));
        LInformacion.setText("Aqui Texto - Informacion | Validacion | Ayuda y demas ");

        javax.swing.GroupLayout PanelInformacionLayout = new javax.swing.GroupLayout(PanelInformacion);
        PanelInformacion.setLayout(PanelInformacionLayout);
        PanelInformacionLayout.setHorizontalGroup(
            PanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelInformacionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(IconoInformacion)
                .addGap(28, 28, 28)
                .addComponent(LInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, 1003, Short.MAX_VALUE))
        );
        PanelInformacionLayout.setVerticalGroup(
            PanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(IconoInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(LInformacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout panelColapsableLayout = new javax.swing.GroupLayout(panelColapsable.getContentPane());
        panelColapsable.getContentPane().setLayout(panelColapsableLayout);
        panelColapsableLayout.setHorizontalGroup(
            panelColapsableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PanelInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        panelColapsableLayout.setVerticalGroup(
            panelColapsableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PanelInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        inicio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/ribbon.png"))); // NOI18N
        inicio.setMargin(new java.awt.Insets(0, 2, 0, 5));

        configuracion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/config32.png"))); // NOI18N
        configuracion.setText("Configuración");
        configuracion.setName("configuracion"); // NOI18N

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/usuarios32.png"))); // NOI18N
        jMenuItem5.setText("Usuarios/Permisos");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        configuracion.add(jMenuItem5);

        backups.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/backup32.png"))); // NOI18N
        backups.setText("Backups");
        configuracion.add(backups);

        inicio.add(configuracion);

        salir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/exit login.png"))); // NOI18N
        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });
        inicio.add(salir);

        Menu.add(inicio);

        pacientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/pacientes32.png"))); // NOI18N
        pacientes.setText("Pacientes");

        Paciente_View_Grid.setText("Consultar Pacientes");
        Paciente_View_Grid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Paciente_View_GridActionPerformed(evt);
            }
        });
        pacientes.add(Paciente_View_Grid);

        Paciente_View_Add.setText("Agregar Paciente");
        Paciente_View_Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Paciente_View_AddActionPerformed(evt);
            }
        });
        pacientes.add(Paciente_View_Add);
        pacientes.add(jSeparator1);

        Acudiente_View_Grid.setText("Consultar Acuedientes");
        Acudiente_View_Grid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Acudiente_View_GridActionPerformed(evt);
            }
        });
        pacientes.add(Acudiente_View_Grid);

        Acudiente_View_Add.setText("Agregar Acudiente");
        Acudiente_View_Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Acudiente_View_AddActionPerformed(evt);
            }
        });
        pacientes.add(Acudiente_View_Add);

        Menu.add(pacientes);

        medicos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/doctor32.png"))); // NOI18N
        medicos.setText("Medicos");

        jMenuItem7.setText("Consultar Médicos");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        medicos.add(jMenuItem7);

        jMedicoItem.setText("Agregar Médico");
        jMedicoItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMedicoItemActionPerformed(evt);
            }
        });
        medicos.add(jMedicoItem);

        jMenuItem11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/trazabilidad32.png"))); // NOI18N
        jMenuItem11.setText("Trazabilidad");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        medicos.add(jMenuItem11);

        Menu.add(medicos);

        citas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/citas32.png"))); // NOI18N
        citas.setText("Citas");

        jMenuItem8.setText("Agenda Medica");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        citas.add(jMenuItem8);

        jMenuItem9.setText("Citas Medicas");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        citas.add(jMenuItem9);

        Menu.add(citas);

        historia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/h.c.32.png"))); // NOI18N
        historia.setText("Historia Clinica");
        historia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historiaActionPerformed(evt);
            }
        });

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/valoracion.png"))); // NOI18N
        jMenuItem1.setText("Valoración");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        historia.add(jMenuItem1);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/trazabilidad32.png"))); // NOI18N
        jMenuItem2.setText("Trazabilidad");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        historia.add(jMenuItem2);

        Menu.add(historia);

        setJMenuBar(Menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(PanelConstructor, javax.swing.GroupLayout.DEFAULT_SIZE, 1116, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 268, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 242, Short.MAX_VALUE)
                                        .addComponent(lModulo, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lAccion, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                                .addGap(378, 378, 378)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panelColapsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(19, 19, 19))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false)
                    .addComponent(lModulo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(lAccion, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(PanelConstructor, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelColapsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
    constructor("Planilla_View_Grid");
    }//GEN-LAST:event_jMenuItem8ActionPerformed

private void Acudiente_View_AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Acudiente_View_AddActionPerformed
    constructor("Acudiente_View_Add", "INSERT", "");
}//GEN-LAST:event_Acudiente_View_AddActionPerformed

private void Acudiente_View_GridActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Acudiente_View_GridActionPerformed
    constructor("Acudiente_View_Grid");
}//GEN-LAST:event_Acudiente_View_GridActionPerformed

private void Paciente_View_AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Paciente_View_AddActionPerformed
    constructor("Paciente_View_Add", "INSERT", "");
}//GEN-LAST:event_Paciente_View_AddActionPerformed

private void Paciente_View_GridActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Paciente_View_GridActionPerformed
    constructor("Paciente_View_Grid");
}//GEN-LAST:event_Paciente_View_GridActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        // TODO add your handling code here:
        constructor("Cita_View_Grid");
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void lModuloMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lModuloMouseClicked
        if (navegar != null && !navegar.isEmpty()) {
            constructor(getNavegar());
        }

    }//GEN-LAST:event_lModuloMouseClicked

    private void lModuloMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lModuloMouseEntered
        //Cambiar el Color
        lModulo.setForeground(new Color(102, 102, 102));
        //Resaltar cuando pasen el mouse por encima
        lModulo.setText("<html><u>" + lModulo.getText() + "</u></html>");
        //Cambiar Tipo de Icono
        lModulo.setCursor(new Cursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_lModuloMouseEntered

    private void lModuloMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lModuloMouseExited
        //Cambiar el Color
        lModulo.setForeground(Color.BLACK);
        //Reseatar Formato de Texto
        lModulo.setText(getLabelModulo());
        //Colocar Cursos por Defecto
        lModulo.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_lModuloMouseExited

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        constructor("Trazabilidad");
    }//GEN-LAST:event_jMenuItem11ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // TODO add your handling code here:
        constructor("Medico_View_Grid");
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMedicoItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMedicoItemActionPerformed
        // TODO add your handling code here:
        constructor("Medico_View_Add", "INSERT", "");
    }//GEN-LAST:event_jMedicoItemActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        ventPrincipal();
    }//GEN-LAST:event_jLabel1MouseClicked

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_salirActionPerformed

    private void historiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historiaActionPerformed
        constructor("TestNeuro_View_Grid");
    }//GEN-LAST:event_historiaActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        constructor("TestNeuro_View_Grid");
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        constructor("Trazabilidad");
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        
        abrirParametrizacion();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(constructor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(constructor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(constructor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(constructor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new constructor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Acudiente_View_Add;
    private javax.swing.JMenuItem Acudiente_View_Grid;
    private javax.swing.JLabel IconoInformacion;
    private javax.swing.JLabel LInformacion;
    private javax.swing.JMenuBar Menu;
    private javax.swing.JMenuItem Paciente_View_Add;
    private javax.swing.JMenuItem Paciente_View_Grid;
    private javax.swing.JPanel PanelConstructor;
    private org.jdesktop.swingx.JXPanel PanelInformacion;
    private javax.swing.JMenuItem backups;
    private javax.swing.JMenu citas;
    private javax.swing.JMenu configuracion;
    private javax.swing.JMenu historia;
    private javax.swing.JMenu inicio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMedicoItem;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JLabel lAccion;
    private javax.swing.JLabel lModulo;
    private javax.swing.JMenu medicos;
    private javax.swing.JMenu pacientes;
    private org.jdesktop.swingx.JXCollapsiblePane panelColapsable;
    private javax.swing.JMenuItem salir;
    // End of variables declaration//GEN-END:variables

    //este metodo se llama igual que el constructor
    public void constructor(String pantalla, String... opc) {
        System.out.println(pantalla);

        panelColapsable.setCollapsed(true);
        ocultarMensaje.setIniciar(false);
        if (pantalla.equals("p1")) {
        } else if (pantalla.equals("Bienve_medico")) {
            JPanel p4 = new core.constructor.init_medico(this);
            p4.setName("bienvenida");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Bienve_secretario")) {
            JPanel p4 = new core.constructor.init_secretario(this);
            p4.setName("Bienve_secretario");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Acudiente_View_Add")) {
            JPanel p4 = new Acudiente_View_Add(this, opc[0], opc[1]);
            p4.setName("Acudiente_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Acudiente_View_Grid")) {
            JPanel p4 = new Acudiente_View_Grid(this);
            p4.setName("Acudiente_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Paciente_View_Add")) {
            JPanel p4 = new Paciente_View_Add(this, opc[0], opc[1]);
            p4.setName("Paciente_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Paciente_View_Grid")) {
            JPanel p4 = new Paciente_View_Grid(this);
            p4.setName("Paciente_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p4.setVisible(true);
        } else if (pantalla.equals("Medico_View_Add")) {
            JPanel p6 = new Medico_View_Add(this, opc[0], opc[1]);
            p6.setName("Medico_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p6);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p6.setVisible(true);
        } else if (pantalla.equals("Medico_View_Grid")) {
            JPanel p7 = new Medico_View_Grid(this);
            p7.setName("Medico_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        } else if (pantalla.equals("Planilla_View_Grid")) {
            JPanel p7 = new Planilla_View_Grid(this);
            p7.setName("Planilla_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        } else if (pantalla.equals("Planilla_View_Add")) {
            JPanel p7 = new Planilla_View_Add(this, opc[0], opc[1]);
            p7.setName("Planilla_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            p7.setVisible(true);
        } else if (pantalla.equals("Cita_View_Grid")) {
            JPanel p7 = new Cita_View_Grid(this);
            p7.setName("Cita_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        } else if (pantalla.equals("Cita_View_Add")) {
            JPanel p7 = new Cita_View_Add(this, opc[0], opc[1]);
            p7.setName("Cita_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        } else if (pantalla.equals("TestNeuro_View_Grid")) {
            JPanel p7 = new TestNeuro_View_Grid(this);
            p7.setName("TestNeuro_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        } else if (pantalla.equals("Trazabilidad")) {
            JPanel p7 = new Trazabilidad(this);
            p7.setName("Trazabilidad");
            PanelConstructor.removeAll();
            PanelConstructor.add(p7);
            this.validate();
            //p4.setBounds(0, 0, 453, 189);
            p7.setVisible(true);
        }else if (pantalla.equals("Medicamentos_View_Add")) {
            JPanel p4 = new Medicamentos_View_Add(this, opc[0], opc[1]);
            p4.setName("Medicamentos_View_Add");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            p4.setVisible(true);
        } else if (pantalla.equals("Medicamentos_View_Grid")) {
            JPanel p4 = new Medicamentos_View_Grid(this);
            p4.setName("Medicamentos_View_Grid");
            PanelConstructor.removeAll();
            PanelConstructor.add(p4);
            this.validate();
            p4.setVisible(true);
        }else if (pantalla.equals("UsuariosAdmin_View_Add")) {
            //UsuariosAdmin_View_Add u = new UsuariosAdmin_View_Add();
            JPanel p4 = new UsuariosAdmin_View_Add(this, opc[0], opc[1]);
            p4.setName("UsuariosAdmin_View_Add");
            usuarios.PanelConstructor.removeAll();
            usuarios.PanelConstructor.add(p4);
            this.validate();
            p4.setVisible(true);
        }else if (pantalla.equals("UsuariosAdmin_View_Grid")) {
            //UsuariosAdmin_View_Add u = new UsuariosAdmin_View_Add();
            JPanel p4 = new UsuariosAdmin_View_Grid(this);
            p4.setName("UsuariosAdmin_View_Grid");
            usuarios.PanelConstructor.removeAll();
            usuarios.PanelConstructor.add(p4);
            this.validate();
            p4.setVisible(true);
        }


    }

    public void setMensaje(String msj) {
        LInformacion.setText(msj);
    }

    public String getMensaje() {
        return LInformacion.getText();
    }

    public String getRol() {
        return rol;
    }

    public void setRol(String rol) {
        this.rol = rol;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getNavegar() {
        return navegar;
    }

    public void setNavegar(String navegar) {
        this.navegar = navegar;
    }

    public String getLabelAccion() {
        return lAccion.getText();
    }

    public void setLabelAccion(String txt) {
        System.out.println("Texto para Accion " + txt);
        lAccion.setText(txt);
    }

    public String getLabelModulo() {
        return lModulo.getText();
    }

    public void setLabelModulo(String txt) {
        lModulo.setText(txt);
    }

    /**
     * <p>Asingar Texto/Icono a la Barra de Ayuda de la Aplicacion</p> <br>
     *
     * @param modo <br> <ul> <li><strong>help: </strong>Informacion en
     * General</li> <li><strong>ok: </strong>Mostrar Cuando Accion/Evento se
     * hizo correctamente</li> <li><strong>error: </strong>Mostrar cuando
     * Accion/Evento no se realizo correctamente</li> </ul>
     *
     * @param txt <br> Texto de Ayuda que se va a incluir.
     */
    public void setToolTip(String modo, String txt) {
        String rutaImg = "/core/img/";
        panelColapsable.setCollapsed(false);
        ocultarMensaje.setIniciar(true);
        if (!ocultarMensaje.isIniciado()) {
            (new Thread(ocultarMensaje)).start();
        }

        if (modo.equals("help")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "help64.png")));
            PanelInformacion.setBackground(new java.awt.Color(189, 229, 248)); //rgb(189, 229, 248)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(47, 119, 178))); //rgb(47, 119, 178)
            LInformacion.setForeground(new java.awt.Color(0, 82, 162)); //rgb(0, 82, 162)
        } else if (modo.equals("ok")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "ok64.png")));
            PanelInformacion.setBackground(new java.awt.Color(254, 239, 179)); //rgb(254, 239, 179)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(159, 99, 52))); //rgb(159, 99, 52)
            LInformacion.setForeground(new java.awt.Color(159, 99, 52));
        } else if (modo.equals("error")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "error64.png")));
            PanelInformacion.setBackground(new java.awt.Color(255, 186, 186)); //rgb(255, 186, 186)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(222, 0, 12))); //rgb(222, 0, 12)
            LInformacion.setForeground(new java.awt.Color(222, 0, 12));
        }
        setMensaje(txt);
    }

    public void informarUsuario(String txt) {
        if (!txt.isEmpty()) {
            String modo = txt.substring(0, txt.indexOf("["));
            String mensajeHTML = String.format("<html><p><font size=\"8\">%s</font></p><p><font size=\"5\">%s</font></p></html>", txt.substring(txt.indexOf("[") + 1, txt.indexOf("]")), txt.substring(txt.lastIndexOf("]") + 1));
            setToolTip(modo, mensajeHTML);
        }
    }

    void setAccess(List<String> modulos , String rol, String usuario){
        setRol(rol);
        setUsuario(usuario);
        
        if(!"administrador".equals(rol)){            
        
            if(!modulos.contains("inicio")){
                inicio.setVisible(false);
                System.out.println("No contiene inicio ...");
            }
            if(!modulos.contains("pacientes")){
                pacientes.setVisible(false);
            }
            if(!modulos.contains("medicos")){
                medicos.setVisible(false);
            }
            if(!modulos.contains("citas")){
                citas.setVisible(false);
            }
            if(!modulos.contains("historias")){
                historia.setVisible(false);
            }
        }
    }
    void setAccess1(String cadenaS) {
        System.out.println("cadenaS " + cadenaS);
        String[] user = cadenaS.split(",");

        setUsuario(user[0]);
        setRol(user[1]);
        System.out.println("user[2] " + user[2]);
        String permisos = user[2];
        ArrayList permiso = new ArrayList();
        permiso.addAll(Arrays.asList(user[2].split("\\|")));


        System.out.println("Permisos Tamanio " + permiso.size());
        Object[] e = Menu.getComponents();

        System.out.println("Numero de Menus : " + e.length);
        for (int i = 0; i < e.length; i++) {
            JMenu modulo = (JMenu) e[i];



            if (!permiso.contains(modulo.getName())) {
                //System.out.println(modulo.getName() + " |no contenida!");
                modulo.setVisible(false);
            }

//////            //Segundo Anillo
//            Object[] eiE = modulo.getComponentListeners();
//            System.out.println("Size => " + eiE.length);
//            for (int i2 = 0; i2 < eiE.length; i2++) {
//                JMenu subModulo = (JMenu) eiE[i2];
//                System.out.println("WTF!!!!!   " + subModulo.getClass().getName());
//                if (!permiso.contains(subModulo.getName())) {
//                    System.out.println(subModulo.getName() + " |no contenida!");
//                    subModulo.setVisible(false);
//                }
//            }



        }
    }

    public void ventanaEmergente(String sqlTabla, String titulosColumas, constructor c, String urlClase, String metodo) {
        SeleccionadorIU select = new SeleccionadorIU(sqlTabla, titulosColumas, c, urlClase, metodo);
        select.setVisible(true);
        select.setBounds(0, 0, 453, 189);


    }

    /*
     * Retornar a Ventana principal
     * de acuerdo al rol correspondiente
     */
    public void ventPrincipal() {
        constructor("Bienve_" + getRol());
    }

    /**
     * Implementacion de Volver a Atras en la Interfaz. Por lo regular se
     * retorna a la tabla que representa el modulo.
     *
     * @param ui
     */
    public void goBack(String ui) {
        constructor(ui);
    }

    public void infoUsuario(String modo, String mensaje, String titulo) {
        if (!mensaje.isEmpty() || !titulo.isEmpty()) {
            String t = String.format("<p><font size=\"7\">%s</font></p>", titulo); //Titulo Mensaje
            String msj = String.format("<p><font size=\"5\">%s</font></p>", mensaje); // Mensaje
            String mensajeHTML = String.format("<html>%s%s</html>", titulo == null ? "" : t, mensaje == null ? "" : msj);
            setToolTip(modo, mensajeHTML);
        } else {
            Logger.getLogger(constructor.class.getName()).log(Level.WARNING, "No es posible agregar mensaje, el contenido de este se encuentra vacio.");
        }
    }

    public void infoUsuario(String modo, String mensaje) {
        infoUsuario(modo, mensaje, null);
    }
}
